﻿@using doufu.WebUI
@model doufu.Model.users
@{
    ViewBag.Title = "用户登录";
}
<h2>
    用户登录</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>登录信息</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.user_name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.user_name)
            @Html.ValidationMessageFor(model => model.user_name)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.password)
            @Html.ValidationMessageFor(model => model.password)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.RememberMe)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.RememberMe)
            @Html.ValidationMessageFor(model => model.RememberMe)
        </div>
        <p>
            <input type="submit" value="登录" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("返回主页", "Index", "Home")
    <script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc.js"
        charset="utf-8"></script>
    <span id="qqLoginBtn"></span>
    <script type="text/javascript">
        QC.init({ appId: "@(Config.QQApiKey)" });

        QC.Login({
            btnId: "qqLoginBtn", size: "C_S", scope: "get_user_info", display: "pc"
        }, function (reqData, opts) {//登录成功
            var dom = document.getElementById(opts['btnId']),
                _logoutTemplate = [
            //头像
                    '<span><img src="{figureurl}" class="{size_key}"/></span>',
            //昵称
                    '<span>{nickname}</span>',
            //退出
                    '<span><a href="javascript:QC.Login.signOut();">退出</a></span>'
                ].join("");
            dom && (dom.innerHTML = QC.String.format(_logoutTemplate, {
                nickname: QC.String.escHTML(reqData.nickname),
                figureurl: reqData.figureurl
            }));

            if (QC.Login.check()) {
                QC.Login.getMe(function (openId, accessToken) {
                    $.post('@Url.Action("LogOnOpen")', { openId: openId, accessToken: accessToken }, function (r) { if (r == "1") { location = '@Url.Action("Index","Home")'; } else { alert(r); } });
                });
            }
        }, function (opts) {//注销成功
            alert('QQ登录 注销成功');
        });
    </script>
</div>
